package com.amumu.drama.common.modules.invitation.mapping;

import com.amumu.drama.common.base.mapstruct.BaseMapping;
import com.amumu.drama.common.base.mapstruct.ext.LocalDateTimeToStringMapping;
import com.amumu.drama.common.modules.invitation.dto.resp.MemberInvitationLogListResp;
import com.amumu.drama.common.modules.member.cache.MemberCache;
import com.amumu.drama.model.InvitationLog;
import com.amumu.drama.model.UmsMember;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * @author sunzhuang
 * @date 2024/9/13 10:55
 * @slogan 天下风云出我辈, 一入代码岁月催
 * @desc todo
 */
@Mapper(componentModel = "spring")
public interface MemberInvitationLogListRespMapping extends BaseMapping<InvitationLog, MemberInvitationLogListResp>, LocalDateTimeToStringMapping {
    MemberInvitationLogListRespMapping INSTANCE = Mappers.getMapper(MemberInvitationLogListRespMapping.class);

    /**
     * 正向映射的后置处理，List映射会自动继承此配置
     *
     * @param src
     * @param dest
     */
    @Override
    default void afterConvertTo(InvitationLog src, MemberInvitationLogListResp dest) {
        UmsMember member = MemberCache.INSTANCE.getFromCache(dest.getInviteeMemberId());
        if (member != null) {
            dest.setInviteePhone(member.getPhone());
        }
    }
}
